/******************************************************************************************************
Copyright (C) 2010 Mestrelab Research S.L. All rights reserved.

This file is part of the MNova scripting toolkit.

Authorized users of MNova Software may use this file freely, but this file is provided AS IS
with NO WARRANTY OF ANY KIND, INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE.
*****************************************************************************************************/

function cloningObjects()
{
	var w = mainWindow.activeDocument
	var p = w.curPage()

//Create some items
	var text = draw.text("<b>This is text</b>", true)
	text.translate(200,200)
	text.color="cyan"
	print(text)
	print(text.plainText)

	var rect = draw.rectangle(p.width/3,p.height/3);
	rect.translate(50, 75);
	rect.angle = 45;
	rect.color = "red";
	rect.opacity=50;
	print(rect);
	
	var arrow = draw.arrow(p.right, p.top, p.left, p.bottom, false, true);
	arrow.startX = (p.right+p.left)/2.0;
	arrow.startY = p.top+100;
	arrow.lineColor="blue";
	arrow.lineStyle = PageItem.DashLine;
	print(arrow);

	var ellipse = draw.ellipse(p.width/2,p.height/2);
	ellipse.angle=90;
	ellipse.lineStyle=PageItem.DashDotLine;
	//ellipse.color = "pink";
	print(ellipse);

//create a new page
	var newPage = w.newPage()

//clone the text item in the new page
	var clonedItem = newPage.cloneItems(text);
	print("cloned Item "+clonedItem);

//another page and clone the rectangle and the arrow there
	newPage = w.newPage()
	var itemArray = []
	itemArray[0] = rect;
	itemArray[1] = arrow;

	var clonedArray = newPage.cloneItems(itemArray);
	print("number of clones "+clonedArray.length);

//clone the entire page
	var anotherPage = w.clonePages(newPage);
	print(anotherPage);

	//newPage.deleteItems(clonedArray);
	//print(clonedArray[0]);

	w.update();
}

function editingPages() {
	var w = mainWindow.activeDocument
	draw.text("Initial Page", true);
	
	w.addPage();
	draw.text("Added at end", true);

	w.addPage(1);
	draw.text("Inserted at 1", true);

	var pageToMove = new Page(w.addPage());
	draw.text("Page added to the end and moved to 1", true);
	w.movePages(1, pageToMove);

	var pageToMove2 = w.addPage();
	draw.text("Pages added to the end and moved to 2", true);
	var pageToMove3 = w.addPage();
	draw.text("Pages added to the end and moved to 2", true);
	w.movePages(2, [pageToMove2, pageToMove3]);

	w.update();	
}
